﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Blog.Models.Entities;
using MvcEngine.Core.Validation;
using MvcEngine.Core.Base;
using MvcEngine.Core.Utils;
using System.Xml.Linq;

namespace MvcEngine.Blog.Models.Entities
{
    public class BlogData : Entity, IModule
    {
        public Guid Id { get; set; }

        [LengthValidator("BlogNameLengthValidator", 256)]
        [RequiredFieldValidator("BlogNameRequiredValidator")]
        public string Name { get; set; }

        public Guid PageId { get; set; }

        public bool AllowComments 
        {
            get { return this.GetValue<bool>("AllowComments", false); }
            set { Fields.SetValue("AllowComments", value); } 
        }

        public bool ShowCaptcha
        {
            get { return this.GetValue<bool>("ShowCaptcha", false); }
            set { Fields.SetValue("ShowCaptcha", value); }
        }

        [LengthValidator("BlogDescriptionLengthValidator", 256)]
        public string BlogDescription 
        {
            get { return (string)Fields.GetValue("BlogDescription"); }
            set { Fields.SetValue("BlogDescription", value); } 
        }

        [LengthValidator("BlogTitleLengthValidator", 256)]
        public string BlogName 
        {
            get { return (string)Fields.GetValue("BlogName"); }
            set { Fields.SetValue("BlogName", value); } 
        }

        public int DaysCommentsAreEnabled 
        {
            get { return this.GetValue<int>("DaysCommentsAreEnabled", 0); }
            set { Fields.SetValue("DaysCommentsAreEnabled", value); } 
        }

        public int PostsInRss
        {
            get { return this.GetValue<int>("PostsInRss", 10); }
            set { Fields.SetValue("PostsInRss", value); }
        }

        [LengthValidator("BlogEmailLengthValidator", 256)]
        public string Email
        {
            get { return (string)Fields.GetValue("Email"); }
            set { Fields.SetValue("Email", value); }
        }

        [LengthValidator("BlogEmailSubjectPrefixLengthValidator", 256)]
        public string EmailSubjectPrefix
        {
            get { return (string)Fields.GetValue("EmailSubjectPrefix"); }
            set { Fields.SetValue("EmailSubjectPrefix", value); }
        }

        public string HtmlHeader
        {
            get { return (string)Fields.GetValue("HtmlHeader"); }
            set { Fields.SetValue("HtmlHeader", value); }
        }

        public int PostsPerPage
        {
            get { return this.GetValue<int>("PostsPerPage", 5); }
            set { Fields.SetValue("PostsPerPage", value); }
        }

        public bool SendMailOnComment
        {
            get { return this.GetValue("SendMailOnComment", false); }
            set { Fields.SetValue("SendMailOnComment", value); }
        }

        [LengthValidator("BlogSmtpPasswordLengthValidator", 256)]
        public string SmtpPassword
        {
            get { return (string)Fields.GetValue("SmtpPassword"); }
            set { Fields.SetValue("SmtpPassword", value); }
        }

        [LengthValidator("BlogSmtpServerLengthValidator", 256)]
        public string SmtpServer
        {
            get { return (string)Fields.GetValue("SmtpServer"); }
            set { Fields.SetValue("SmtpServer", value); }
        }

        public int SmtpServerPort
        {
            get { return this.GetValue<int>("SmtpServerPort", 25); }
            set { Fields.SetValue("SmtpServerPort", value); }
        }

        [LengthValidator("BlogSmtpUserNameLengthValidator", 256)]
        public string SmtpUserName
        {
            get { return (string)Fields.GetValue("SmtpUserName"); }
            set { Fields.SetValue("SmtpUserName", value); }
        }

        public override string Xml { get; set; }

        public DateTime CreatedDate { get; set; }

        public DateTime ModifiedDate { get; set; }
    }
}
